package com.Jning.cfengtestdemo.matcher;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;

/**
 * @author Cfeng
 * @date 2022/7/26
 */

public class isCfengWorldMatcher extends BaseMatcher<String> {

    public static <T> Matcher<String> isCfengWorld() {
        //返回匹配器示例，就是一个单例
        return new isCfengWorldMatcher();
    }

    //匹配的业务逻辑
    @Override
    public boolean matches(Object actual) {
        if(actual == null) {
            return false;
        }
        String s = (String)actual;
        return s.startsWith("Cfeng") && s.endsWith("World");
    }
    //对输入项的描述，在断言失败的时候就会打印到console中
    @Override
    public void describeTo(Description description) {
        description.appendText("a string that start with \"Cfeng\" and end with \"World\"");
    }
}
